home *** CD-ROM | disk | FTP | other *** search
- /*
- File: TDocument.h
-
- Contains: TDocument interface
-
- Copyright: © 1991-1994 by Apple Computer, Inc., all rights reserved.
-
- */
-
-
- #ifndef __DOCUMENT__
- #define __DOCUMENT__
-
- #ifndef __LIBRARYMANAGERCLASSES__
- #include <LibraryManagerClasses.h>
- #endif
-
-
- /*******************************************************************************
- ** Forward declarations
- ********************************************************************************/
-
- class TDocument;
- class TDocumentLink;
- class TDocumentList;
- struct EventRecord;
- struct GrafPort;
-
-
- // Define HiWrd and LoWrd macros for efficiency
- #define HiWrd(aLong) ((short) (((aLong) >> 16) & 0xFFFF))
- #define LoWrd(aLong) ((short) ((aLong) & 0xFFFF))
-
- // Define TopLeft and BotRight macros for convenience. Notice the implicit
- // dependency on the ordering of fields within a Rect
- #define TopLeft(aRect) (* (Point *) &(aRect).top)
- #define BotRight(aRect) (* (Point *) &(aRect).bottom)
-
- const long kMaxSleepTime = 60; // 1 second worth of ticks
-
- /**********************************************************************
- ** class TDocument
- ***********************************************************************/
-
- #define kTDocumentID "appl:insp$TDocument,1.2"
-
- class TDocument : public TDynamic
- {
- public:
- TDocument();
- TDocument(short resID); // creates window using resID as template
- virtual ~_CDECL TDocument(); // disposes of window
-
- // you will need to override these in your subclasses,
- // since they are do-nothing routines by default...
- virtual void DoZoom(short partCode);
- virtual void DoGrow(EventRecord* theEvent);
- virtual void DoContent(EventRecord* theEvent);
- virtual void DoKeyDown(EventRecord* theEvent);
- virtual void DoActivate(Boolean becomingActive);
- virtual void DoUpdate();
- // file handling routines
- virtual void DoOpen();
- virtual void DoClose();
- virtual void DoSave();
- virtual void DoSaveAs();
- virtual void DoRevert();
- virtual void DoPrint();
- // do standard edit menu actions
- virtual void DoUndo();
- virtual void DoCut();
- virtual void DoCopy();
- virtual void DoPaste();
- virtual void DoClear();
- virtual void DoSelectAll();
-
- // idle time routines: you can use these to do cursor handling,
- // TE caret blinking, marquee effects, etc...
- virtual void DoIdle();
- virtual unsigned long CalcIdle();
- virtual void AdjustCursor(Point where); // where is in local coords
-
- // query state of document - useful for adjusting menu state
- virtual Boolean HaveUndo();
- virtual Boolean HaveSelection();
- virtual Boolean HavePaste();
- virtual Boolean CanClose();
- virtual Boolean CanSave();
- virtual Boolean CanSaveAs();
- virtual Boolean CanRevert();
- virtual Boolean CanPrint();
-
- GrafPort* GetDocWindow() { return fDocWindow;} ;
- TDocumentList* GetDocList() { return fDocList; };
- void SetDocList(TDocumentList *theDocList) { fDocList = theDocList; };
-
- protected:
- GrafPort* fDocWindow;
- TDocumentList *fDocList;
-
- private:
- virtual void InitDocument(short resID);
- };
-
-
- /**********************************************************************
- ** class TDocumentList
- ***********************************************************************/
-
- #define kTDocumentListID "appl:insp$TDocumentList,1.2"
-
- // TDocumentList is a simple linked list of documents, implemented C++
- // style. I could have made a general linked list class & just made
- // this a subclass. This would have been a more general (and more
- // object-oriented) solution, but I did it from scratch in a futile
- // attempt at keeping the size of this program at a reasonable level.
-
- class TDocumentList : public TDynamic
- {
- TDocumentLink* fDocList; // the first link in our list
- int fNumDocs; // the number of elements in the list
-
- public:
- TDocumentList(); // our constructor
- virtual ~_CDECL TDocumentList(); // our destructor
-
- virtual void AddDoc(TDocument* doc);
- virtual void RemoveDoc(TDocument* doc);
- virtual TDocument* FindDoc(GrafPort* window);
- inline int NumDocs() { return fNumDocs; }
- inline TDocumentLink* FirstDoc() { return fDocList; }
- };
-
-
- /**********************************************************************
- ** class TDocumentLink
- ***********************************************************************/
-
- // TDocumentLink is a simple utility class which is used by
- // the TDocumentList class below. You cannot allocate
- // objects of this type yourself, since its constructor
- // is private. We get around this for TDocumentList by
- // making it a "friend" of this class. This is a handy
- // trick.
- class TDocumentLink : public TLink
- {
- friend class TDocumentList;
-
- // our constructor. Note that it can take args for convenience,
- // but that they default to NULL.
- TDocumentLink(TDocumentLink *n = NULL, TDocument *v = NULL);
- ~TDocumentLink() {};
-
- void SetDoc(TDocument* aDoc) { SetValue(aDoc); };
-
- public:
- TDocumentLink* GetNext() { return (TDocumentLink*)TLink::GetNext(); };
- TDocument* GetDoc() { return (TDocument*)GetValue(); };
- };
-
-
- inline TDocumentLink::TDocumentLink(TDocumentLink* n, TDocument* v) :
- TLink(n, v)
- {}
-
- #endif
-